<?php


namespace app\common\model;


class UserPlatformModel extends CommonModel
{
    protected $name = 'user_platform';
    //    public function getIsDefaultAttr($v): bool
    //    {
    //        return $v === 1;
    //    }
    //
    //    public function setCreateTimeAttr($timestamp)
    //    {
    //        return date('Y-m-d H:i:s', $timestamp);
    //    }
    //
    //    public function setIsDefaultAttr($v): int
    //    {
    //        return $v === true ? 1 : 0;
    //    }

    public function userInfo(): \think\model\relation\hasOne
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id');
    }

    //    public function xxxxxInfo()
    //    {
    //        return $this->belongsToMany(RoleModel::class, GroupRoleModel::class,'role_id','group_id');
    //    }

    public function getUserPlatformList($where = [],$field= '*',$whereOr = [])
    {
        $conn = $this->with(
            [
                'userInfo',
            ]
        )->order(
            [
                'create_time' => 'desc',
            ]
        )->where($where)->append(
            []
        );
        foreach ($whereOr as $item) {
            $conn->whereOr($item);
        }
        return $conn->field($field)->select();
    }

    public function getUserPlatformListPaginate($where = [], $page = 1, $limit = 10)
    {
        return $this->with(['userInfo'])->order(
            [
                'create_time' => 'desc',
            ]
        )->where($where)->append(
            []
        )->paginate(
            [
                'page'      => $page,
                'list_rows' => $limit,
            ]
        );
    }

    public function getUserPlatform($where = [], $field = '*', $whereOr = [])
    {
        $conn = $this->with(['userInfo'])->order(
            [
                'create_time' => 'desc',
            ]
        )->where($where)->append(
            []
        )->field($field)->find();
        foreach ($whereOr as $item) {
            $conn->whereOr($item);
        }
        return $conn->field($field)->find();
    }
}